package com.github_Dididipapa.shortlink.admin.controller;

import com.github_Dididipapa.shortlink.admin.common.result.R;
import com.github_Dididipapa.shortlink.admin.common.result.Rs;
import com.github_Dididipapa.shortlink.admin.dto.req.CreateGroupReqDTO;
import com.github_Dididipapa.shortlink.admin.dto.req.UpdateGroupReqDTO;
import com.github_Dididipapa.shortlink.admin.dto.resp.GroupRespDTO;
import com.github_Dididipapa.shortlink.admin.service.GroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: To be defined
 * @author: dididi_papa
 * @email: mitis1624087624@gmail.com
 * @date: 2025/09/10  11:14
 */
@RestController
@RequestMapping("/short-link/admin/v1")
@RequiredArgsConstructor
public class GroupController {

    private final GroupService groupService;

    /**
     * @description: 创建新分组
     * @author: dididi_papa
     * @date: 2025/9/11 下午2:38
     * @param: [group, username]
     * @return: com.github_Dididipapa.shortlink.admin.common.result.R<java.lang.String>
     **/
    @PostMapping("/group")
    public R<String> createGroup(@RequestBody CreateGroupReqDTO group) {

        return Rs.success(groupService.createGroup(group.getName()));
    }

    /**
     * @description: 查询分组集合
     * @author: dididi_papa
     * @date: 2025/9/11 下午2:38
     * @param: [username]
     * @return: com.github_Dididipapa.shortlink.admin.common.result.R<java.util.List<com.github_Dididipapa.shortlink.admin.dto.resp.GroupRespDTO>>
     **/
    @GetMapping("/group")
    public R<List<GroupRespDTO>> getGroup() {
        return Rs.success(groupService.getByUsername());
    }

    /**
     * @description: 修改分组
     * @author: dididi_papa
     * @date: 2025/9/11 下午2:48
     * @param: [group]
     * @return: com.github_Dididipapa.shortlink.admin.common.result.R<java.lang.Boolean>
     **/
    @PutMapping("/group")
    public R<Boolean> updateGroup(@RequestBody UpdateGroupReqDTO group) {
        return Rs.success(groupService.updateGroup(group));
    }

    /**
     * @description: 删除分组
     * @author: dididi_papa
     * @date: 2025/9/12 上午9:30
     * @param: [gid]
     * @return: com.github_Dididipapa.shortlink.admin.common.result.R<java.lang.Boolean>
     **/
    @DeleteMapping("/group")
    public R<Boolean> deleteGroup(@RequestParam String gid) {
        return Rs.success(groupService.removeById(gid));
    }
}
